import java.util.Scanner;
public class time_2025_07_03模拟登陆器 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String correctUsername = "admin";//设置正确用户名
        String correctPassword = "123456";//设置正确密码
        int attempts = 3;

        while(attempts > 0){
            System.out.println("请输入用户名：（还剩"+attempts+"次机会）");
            String inputUsername = scanner.nextLine();
            System.out.println("请输入密码:");
            String inputPassword = scanner.nextLine();

            if(inputUsername.equals(correctUsername)&&inputPassword.equals(correctPassword)){
                System.out.println("登陆成功！");
                break; // 登陆成功，退出循环
            }
            else{
                attempts--;
                if(attempts>0){
                    if(!inputUsername.equals(correctUsername)){
                        System.out.println("用户名错误！请重新输入用户名！还剩"+attempts+"次机会！");
                    }
                    if(!inputPassword.equals(correctPassword)){
                        System.out.println("密码错误！请重新输入密码！还剩"+attempts+"次机会！");
                    }
                }
                else{
                    System.out.println("输入次数过多，退出程序！");
                }
            }

        }
    }
}
